<?php
/**
* alltosun.com  活动控制器
* ============================================================================
* 版权所有 (C) 2009-2015 北京互动阳光科技有限公司，并保留所有权利。
* 网站地址: http://www.alltosun.com
* ----------------------------------------------------------------------------
* 许可声明: 这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
* ============================================================================
* $Author: 张元昊 (zhangyh@alltosun.com) $
* $Date: 2015年08月06日12:14:17 $
* $Id$
*/

class Action
{
    public function __call($action = '', $params = array()) {
        Response::display('m/rockrun_apply.html');
    }


    public function save() {
        $realname = AnFilter::filter_string(trim(Request::Post('realname', '')));
        $mobile   = AnFilter::filter_string(trim(Request::Post('mobile', '')));
        $email    = AnFilter::filter_string(trim(Request::Post('email', '')));

        if(!$realname || !$mobile || !$email) {
            return array('抱歉，所有选项都必须填写', 'error', AnUrl('events/rockrun/index'));
        }

        if(!user_helper::is_email($email)) {
            return array('抱歉，您的邮箱格式不正确！', 'error', AnUrl('events/rockrun/index'));
        }

        if(!user_helper::is_mobile($mobile)) {
            return array('抱歉，您的手机号格式不正确！', 'error', AnUrl('events/rockrun/index'));
        }

        $filter = array(
                    'mobile'   => $mobile,
                    'realname' => $realname,
                    'email'    => $email
            );
        $id = _model('newhit_apply')->create($filter);
        if($id) {
            Response::redirect(AnUrl('events/rockrun/success'));
        } else {
            return array('抱歉，报名失败，请重试！', 'error', AnUrl('events/rockrun/index'));
        }
        
    }

    public function success() {
        Response::display('m/rockrun_success.html');
    }
}

?>